package com.just.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;

/**
 * String和xml互转
 */
public class CovertStringXML {
    public static void main(String[] args){
        try {
            Document document=stringToDoc("<person> <name>James</name> </person>");
            String text=docToString(document);
            System.out.println(text);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    public static String docToString(Document document){
        return document.asXML();
    }
    public static Document stringToDoc(String text) throws DocumentException {
            return DocumentHelper.parseText(text);
    }
}
